package com.gilight.base.controller;

import com.gilight.base.admin.categor.AdminCategoryService;
import com.gilight.base.admin.user.AdminUserService;
import com.gilight.base.base.ResultEntity;
import com.gilight.base.base.exception.ServiceException;
import com.gilight.base.dto.goods.AdminSpuDTO;
import com.gilight.base.model.uni.UserDO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author liken
 * 商品管理控制类
 */
@RestController
@RequestMapping("/web/admin-user")
public class AdminUserController {

    @Autowired
    private AdminUserService adminUserService;



    @ApiOperation(value = "编辑状态")
    @RequestMapping(value = "/edit-status")
    public ResultEntity categoryTree(Long adminId,
                                     Long userId,
                                     Integer status) {
        ResultEntity resultEntity = new ResultEntity();

        try {
            resultEntity.setData(adminUserService.editStatus(adminId,userId,status));
        } catch (ServiceException e) {
            e.printStackTrace();
        };
        return resultEntity;
    }

    /**
     * 创建
     * @return
     */
    @ApiOperation(value = "创建")
    @RequestMapping(value = "/create", method = {RequestMethod.GET})
    public ResultEntity create(
            Long adminId,
            UserDO user) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminUserService.create(adminId,user));
        } catch (ServiceException e) {
            e.printStackTrace();
        };
        return resultEntity;
    }




    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = {RequestMethod.POST})
    public ResultEntity delete(
            Long adminId,
            Long id,
            String nickname) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminUserService.delete(adminId,id,nickname));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }

    @ApiOperation(value = "更新")
    @RequestMapping(value = "/edit")
    public ResultEntity edit(
            Long adminId,
            UserDO user) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminUserService.edit(adminId,user));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }

    @ApiOperation(value = "所有")
    @RequestMapping(value = "/list")
    public ResultEntity  list(
            Long adminId,
            Long id,
            String nickname,
            Integer level,
            Integer gender,
            Integer status,
            Integer pageNo,
            Integer limit) {
        ResultEntity resultEntity = new ResultEntity();
        try {
            resultEntity.setData(adminUserService.list(adminId,id,nickname,level,gender,status,pageNo,limit));
        } catch (ServiceException e) {
            e.printStackTrace();
        }
        return resultEntity;
    }
}
